package com.lu.banktrade.utils;

import lombok.Data;

/**
 * 响应格式
 * @author L
 */
@Data
public class ResultUtil {
    private ResultUtil(){}
    private Integer code;
    private String msg;
    private Object data;

    /**
     * 默认返回
     * @return
     */
    public static ResultUtil success(){
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code =1;
        resultUtil.msg = "success";
        return resultUtil;
    }

    /**
     * 携带成功信息返回
     * @param msg 返回的信息
     * @return
     */
    public static ResultUtil success(String msg){
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code =1;
        resultUtil.msg = msg;
        return resultUtil;
    }

    /**
     * 携带数据的成功方法返回
     * @param data 返回的数据
     * @return
     */
    public static ResultUtil success(Object data){
        ResultUtil resultUtil = success();
        resultUtil.data = data;
        return resultUtil;
    }

    /**
     * 失败默认方法
     * @return
     */
    public static ResultUtil fail(){
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code =0;
        resultUtil.msg = "fail";
        return resultUtil;
    }

    /**
     * 携带失败信息
     * @param msg
     * @return
     */
    public static ResultUtil fail(String msg){
        ResultUtil resultUtil = new ResultUtil();
        resultUtil.code =0;
        resultUtil.msg = msg;
        return resultUtil;
    }

    /**
     * 携带数据失败的方法返回
     * @param data
     * @return
     */
    public static ResultUtil fail(Object data){
        ResultUtil resultUtil = fail();
        resultUtil.data = data;
        return resultUtil;
    }

    /**
     * 携带错误信息和错误数据返回
     * @param msg 错误信息
     * @param data 错误数据
     * @return 返回对象
     */
    public static ResultUtil fail(String msg,Object data){
        ResultUtil resultUtil = fail(msg);
        resultUtil.data = data;
        return resultUtil;
    }
}
